/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var findSecondMinimumValue = function(root) {
  let nodeArr = [];
  function preView(node) {
    if(!node) return;
    nodeArr.push(node.val);
    preView(node.left);
    preView(node.right);
  }
  preView(root);

  nodeArr.sort((a, b) => a - b);
  let min = nodeArr[0];
  for(let i = 0; i < nodeArr.length; i++) {
    if(nodeArr[i] > min) return nodeArr[i];
  }
  return -1;
};
